package View;
import java.awt.Color;
import java.awt.EventQueue;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.HashMap;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import Controller_events.showClassificaEvent;
import Gui_Events.sistemaEvent;

public class Finale_GUI {

	private JFrame frame;
	private JLabel prima_scud;
	private JLabel seconda_scud;
	private JLabel terza_scud;
	private JLabel quarta_scud;
	private JLabel quinta_scud;
	private JLabel sesta_scud;
	private showClassificaEvent event;
	
	JPanel panel_1;
	
	private JLabel nome_primo;
	private JLabel nome_secondo;
	private JLabel nome_terzo;
	private JLabel nome_quarto;
	private JLabel nome_quinto;
	private JLabel nome_sesto;
	private GUI_interface gui;

	private final String path_segnalini="immagini_segnalini_quotazione/";
	private  HashMap<String, String> segnalini;
	private JLabel oro;
	private JLabel argento;
	private JLabel bronzo;


	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Finale_GUI window = new Finale_GUI(new GUI_interface());
					ArrayList<String> clf = new ArrayList<String>();
					clf.add("rosso");
					clf.add("nero");
					clf.add("blu");
					clf.add("bianco");
					clf.add("giallo");
					clf.add("verde");


					
 					showClassificaEvent evt = new showClassificaEvent(null, clf);
 					window.show(evt);
					
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	

	/**
	 * Initialize the contents of the frame.
	 */
	public Finale_GUI(final GUI_interface gui) {
		frame = gui.get_frame();
		frame.setBounds(0, 0, 794, 696);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(null);
		this.gui = gui;
		frame.setTitle("CLASSIFICA E PREMI");
		
		JPanel panel = new JPanel() { //nota che con l'apertura della graffa creiamo una sottoclasse di JPanel
		
			@Override
			protected void paintComponent(Graphics graphics) {
				super.paintComponent(graphics);
				
				ImageIcon legni = new ImageIcon(gui.resizeImage("images/back.png", 347, 696));
				Image legno = legni.getImage();
				graphics.drawImage(legno, 0, 0, null);
			}
		};
		panel.setBounds(0, 0, 347, 696);
		frame.getContentPane().add(panel);
		panel.setLayout(null);
		
		JLabel Classifica = new JLabel("CLASSIFICA");
		Classifica.setFont(new Font("Monotype Corsiva", Font.BOLD, 25));
		Classifica.setForeground(Color.WHITE);
		Classifica.setBounds(100, 10, 186, 32);
		panel.add(Classifica);
		
		JLabel lblNewLabel = new JLabel("1");
		lblNewLabel.setHorizontalAlignment(SwingConstants.CENTER);
		lblNewLabel.setFont(new Font("Monotype Corsiva", Font.PLAIN, 20));
		lblNewLabel.setForeground(Color.WHITE);
		lblNewLabel.setBounds(22, 75, 45, 61);
		panel.add(lblNewLabel);
		
		JLabel label = new JLabel("2");
		label.setHorizontalAlignment(SwingConstants.CENTER);
		label.setFont(new Font("Monotype Corsiva", Font.PLAIN, 20));
		label.setForeground(Color.WHITE);
		label.setBounds(22, 161, 45, 61);
		panel.add(label);
		
		JLabel label_1 = new JLabel("3");
		label_1.setHorizontalAlignment(SwingConstants.CENTER);
		label_1.setFont(new Font("Monotype Corsiva", Font.PLAIN, 20));
		label_1.setForeground(Color.WHITE);
		label_1.setBounds(22, 222, 45, 61);
		panel.add(label_1);
		
		JLabel label_2 = new JLabel("4");
		label_2.setHorizontalAlignment(SwingConstants.CENTER);
		label_2.setFont(new Font("Monotype Corsiva", Font.PLAIN, 20));
		label_2.setForeground(Color.WHITE);
		label_2.setBounds(22, 282, 45, 61);
		panel.add(label_2);
		
		JLabel label_3 = new JLabel("5");
		label_3.setHorizontalAlignment(SwingConstants.CENTER);
		label_3.setFont(new Font("Monotype Corsiva", Font.PLAIN, 20));
		label_3.setForeground(Color.WHITE);
		label_3.setBounds(22, 337, 45, 61);
		panel.add(label_3);
		
		JLabel label_4 = new JLabel("6");
		label_4.setHorizontalAlignment(SwingConstants.CENTER);
		label_4.setFont(new Font("Monotype Corsiva", Font.PLAIN, 20));
		label_4.setForeground(Color.WHITE);
		label_4.setBounds(22, 392, 45, 61);
		panel.add(label_4);
		
		prima_scud = new JLabel("New label");
		prima_scud.setBounds(77, 66, 80, 80);
		panel.add(prima_scud);
		
		seconda_scud = new JLabel("New label");
		seconda_scud.setBounds(77, 154, 68, 68);
		panel.add(seconda_scud);
		
		terza_scud = new JLabel("New label");
		terza_scud.setBounds(77, 226, 53, 54);
		panel.add(terza_scud);
		
		quarta_scud = new JLabel("New label");
		quarta_scud.setBounds(77, 290, 45, 46);
		panel.add(quarta_scud);
		
		quinta_scud= new JLabel("New label");
		quinta_scud.setBounds(77, 345, 45, 46);
		panel.add(quinta_scud);
		
		sesta_scud = new JLabel("New label");
		sesta_scud.setBounds(77, 400, 45, 46);
		panel.add(sesta_scud);
		
		nome_primo = new JLabel("New label");
		nome_primo.setFont(new Font("Monotype Corsiva", Font.PLAIN, 20));
		nome_primo.setForeground(Color.WHITE);
		nome_primo.setBounds(167, 89, 101, 32);
		panel.add(nome_primo);
		
		nome_secondo = new JLabel("New label");
		nome_secondo.setFont(new Font("Monotype Corsiva", Font.PLAIN, 20));
		nome_secondo.setForeground(Color.WHITE);
		nome_secondo.setBounds(167, 171, 101, 32);
		panel.add(nome_secondo);
		
		nome_terzo = new JLabel("New label");
		nome_terzo.setFont(new Font("Monotype Corsiva", Font.PLAIN, 20));
		nome_terzo.setForeground(Color.WHITE);
		nome_terzo.setBounds(167, 236, 101, 32);
		panel.add(nome_terzo);
		
		nome_quarto = new JLabel("New label");
		nome_quarto.setFont(new Font("Monotype Corsiva", Font.PLAIN, 20));
		nome_quarto.setForeground(Color.WHITE);
		nome_quarto.setBounds(167, 296, 101, 32);
		panel.add(nome_quarto);
		
		nome_quinto = new JLabel("New label");
		nome_quinto.setFont(new Font("Monotype Corsiva", Font.PLAIN, 20));
		nome_quinto.setForeground(Color.WHITE);
		nome_quinto.setBounds(167, 351, 101, 32);
		panel.add(nome_quinto);
		
		nome_sesto = new JLabel("New label");
		nome_sesto.setFont(new Font("Monotype Corsiva", Font.PLAIN, 20));
		nome_sesto.setForeground(Color.WHITE);
		nome_sesto.setBounds(167, 406, 101, 32);
		panel.add(nome_sesto);
		
		segnalini=new HashMap<String, String>();
		segnalini.put("nero", path_segnalini+"sqbla.jpg");
		segnalini.put("rosso", path_segnalini+"sqred.jpg");
		segnalini.put("blu", path_segnalini+"sqblu.jpg");
		segnalini.put("verde", path_segnalini+"sqgree.jpg");
		segnalini.put("bianco", path_segnalini+"sqwh.jpg");
		segnalini.put("giallo", path_segnalini+"sqye.jpg");
		
		
		JButton btnNewButton = new JButton("Continua");
		btnNewButton.setBounds(0, 641, 347, 23);
        btnNewButton.addActionListener(new ActionListener() {
			
			public void actionPerformed(ActionEvent e) {
				event.getController().sistema(new sistemaEvent());
				
			}
		});

		panel.add(btnNewButton);
		
		
		JLabel wallpaper = new JLabel("");
		wallpaper.setBounds(0, 452, 347, 219);
		wallpaper.setIcon(new ImageIcon(gui.resizeImage("images/wallpaper.jpg", 347, 222)));
		panel.add(wallpaper);
		
		oro = new JLabel("");
		oro.setBounds(278, 80, 46, 52);
		panel.add(oro);
		
		argento = new JLabel("");
		argento.setBounds(278, 161, 46, 52);
		panel.add(argento);
		
		bronzo = new JLabel("");
		bronzo.setBounds(278, 222, 46, 52);
		panel.add(bronzo);
		
		frame.setEnabled(true);
	}
	public void show(showClassificaEvent evt) {
		this.event=evt;
		frame.setEnabled(true);
		ArrayList<String> classifica = evt.getClassifica();
		nome_primo.setText(classifica.get(0));
		nome_secondo.setText(classifica.get(1));
		nome_terzo.setText(classifica.get(2));
		nome_quarto.setText(classifica.get(3));
		nome_quinto.setText(classifica.get(4));
		nome_sesto.setText(classifica.get(5));
		
		prima_scud.setIcon(new ImageIcon((gui.resizeImage(segnalini.get(classifica.get(0)), 80, 80))));
		seconda_scud.setIcon(new ImageIcon((gui.resizeImage(segnalini.get(classifica.get(1)),68, 68))));
		terza_scud.setIcon(new ImageIcon((gui.resizeImage(segnalini.get(classifica.get(2)), 53, 54))));
		quarta_scud.setIcon(new ImageIcon((gui.resizeImage(segnalini.get(classifica.get(3)), 45, 46))));
		quinta_scud.setIcon(new ImageIcon((gui.resizeImage(segnalini.get(classifica.get(4)), 45, 46))));
		sesta_scud.setIcon(new ImageIcon((gui.resizeImage(segnalini.get(classifica.get(5)), 45, 46))));
		frame.setVisible(true);
		
		
	}
}
